package cn.tedu.quartz.simple;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;

public class SimpleScheduler {
    public static void main(String[] args) throws SchedulerException {
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

        //定义日期
        Date startDate = new Date();
        startDate.setTime(startDate.getTime()+3000); //任务在当前时间3s后执行

        JobDetail jobDetail = JobBuilder.newJob(HelloJob.class)
                .withIdentity("job1", "group1").build();
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "group1")
                .startAt(startDate)
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().repeatSecondlyForever(5)
                .withRepeatCount(4)) //每隔5s执行一次，执行五次停止。默认是0
                .build();
        scheduler.scheduleJob(jobDetail,trigger);
        scheduler.start();
//     scheduler.shutdown();
    }
}
